package com.zx.designpattern.view.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.zx.designpattern.R;
import com.zx.designpattern.base.BaseFragment;
import com.zx.designpattern.utils.interfaceforall.FunctionManager;
import com.zx.designpattern.presenter.BasePresenter;

import butterknife.OnClick;

public class ThreeFragment extends BaseFragment {
    /**
     * 接口名称：最好使用当前类名，保证唯一性！
     */
    public static final String INTERFACE_NAME = ThreeFragment.class.getName();

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;


    public static ThreeFragment newInstance(String param1, String param2) {
        ThreeFragment fragment = new ThreeFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }


    @Override
    protected int getRootViewId() {
        return R.layout.fragment_three;
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @OnClick(R.id.btn1)
    void clickBtn1(View view) {
        //触发已经增加的接口
        FunctionManager.getInstance().invokeFunctionWithParamOnly(INTERFACE_NAME, " 你好！只有参数没有返回值的接口！");
    }

    @OnClick(R.id.btn2)
    void clickBtn2(View view) {
        String str = FunctionManager.getInstance().invokeFunctionWithResultOnly(INTERFACE_NAME, String.class);
        Toast.makeText(getContext(), "addInterfaceForFragment 4 return is " + str, Toast.LENGTH_SHORT).show();
    }


    @Override
    public void showView(int code, Object data) {

    }
}
